#ifndef RIPROUTE_H
#define RIPROUTE_H
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
//#include <windows.h> //For Windows Sleep
#include <time.h>    //For Windows time
#include <unistd.h> //For Linux sleep
#include <sys/time.h> //For Linux time

const int maxR = 6; //最大路由器数量

//路由表项
struct RIP
{
    char name;      //本路由器名称
    int N;          //到目的网络N
    int d;          //距离d
    char X;         //下一跳路由器
    long long time; //上次更新时间
    bool is_valid;  //是否有效
    RIP() { is_valid = true; }
};

class RipRoute{
public:
    RipRoute(std::string graphName,std::string routeName,bool bNext);
    ~RipRoute();

    std::string GetCurrentTime();
    void WriteLogtoFile(const std::string& tag="",const std::string& value="");
    void printGraphRoute();
    std::vector<RIP> Send(std::vector<RIP> r, char c);

    void InitGraph(const std::string& graphFile);
    void InitRoute(const std::string& routeFile);
    void PrintGraph();
    void PrintRoute();
    bool Update();
    void Check();

    void RunNext();
    void RunAll();

private:
    bool bNextRoute;
    std::ofstream m_nextfout;
    std::ofstream m_allfout;
    std::vector<RIP> rip[maxR];   //路由表
    std::vector<char> ve[maxR];   //一个vector<RIP>包含多条记录是一个路由表 ve则可表示路由器分布图邻接表
    std::string strGraphFileName;
    std::string strRouteFileName;
};
#endif // RIPROUTE_H
